<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Login
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<form id="loginForm" action="/login/do" method="post">
<table cellpadding="15" cellspacing="15">
    <tr>
        <td colspan="2">
        
            <h2>Login</h2> 
            or <a href="/signup">Sign Up</a>
        
        </td>
    </tr>
    <tr>
        <td>Username
        </td>
        <td><input class="input" type="text" name="username" />
        </td>
    </tr>
    <tr>
        <td>Password
        </td>
        <td><input class="input" type="password" name="password" />
        </td>
    </tr>
   
    <tr>
        <td><input type="submit"  class="button" value="Login" />
        </td>
        <td>
        </td>
    </tr>
    <tr>
            <td colspan="2">
                <div id="error"></div>
            </td>
        </tr>   
</table>
</form><br />




<div id="results"></div>

<script type="text/javascript">

$(document).ready(function () {

	var options = { dataType:'json',success:LoginCallBack,beforeSubmit:LoginValidate }; 
    $('#loginForm').ajaxForm(options);
    $("input").focus(function () {$(this).css('border-color','#eecc00');$("#error").html("")});
    $("input").blur(function () {$(this).css('border-color','#999');});


      
});
function LoginCallBack(data)
{
    
   if(data.Successful)
   {
       
       var ret = window.location.search.substr(window.location.search.indexOf("=") + 1, window.location.search.length)
       if (ret == "") {
           if (data.ReturnVal == "admin") {
               ret = "/Admin";


           } else { ret = "/home"; }
       }
       window.location = ret;
           
      return true;
   }
   $("#error").html("Bad login. Please try again.");

}
function LoginValidate()
{
    if(document.getElementById("loginForm").username.value != "" && document.getElementById("loginForm").password.value != "")
    {
        return true
    } 
    $("#error").html("Please complete all fields.");
    return false;
}



</script>

</asp:Content>


